<template>
  <div>
    <div class="too">商品列表</div>
    <div class="top">
      <span
        v-for="(item,i) in tap"
        :key="i"
        @click="ert(item)"
        :class="type === item ? 'active' : ''"
      >{{ item }}</span>
    </div>
    <div v-for="item in list" :key="item.id">
      <div class="uu">
        <span>
          <img :src="item.img" alt />
        </span>
        <span>{{ item.name }}</span>
      </div>

      <div class="rr">
        <span>￥588</span>
        <p>1827人付款</p>
        <button @click="$router.push('/index')">+</button>
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
import axios from 'axios'
export default {
  setup() {
    const tap = ref(['推荐', '母婴', '鞋包', '食品', '数码'])
    const type = ref([])
    const list = ref([])


    axios.get('/data.json').then(res => {
      list.value = res.data.cartData
    })
    function ert(i) {
      type.value = i
    }

    return {
      tap,
      type,
      ert,
      list
    }
  }
}
</script>

<style lang="scss" scoped>
.too {
  width: 100%;
  height: 40px;
  line-height: 40px;
  color: rgb(46, 174, 212);
  text-align: center;
}
img {
  width: 90px;
  height: 90px;
}
.rr{
  margin-top: -40px;
}
.uu {
  display: flex;
}
.top {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 50px;
  line-height: 50px;
  background-color: indigo;
  color: #fff;

  span {
    margin: 0 20px;
  }
  .active {
    background-color: rgb(108, 89, 126);
    color: #fff;
  }
}
</style>